﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Game_Engine
{
    public class Rigidbody : Component, IUpdateable
    {
        public Rigidbody()
        {
            Name = "Rigidbody";
            Acceleration = Vector3.Zero;
            Velocity = Vector3.Zero;
            Mass = 1;
            Impulse = Vector3.Zero;
        }

        public void Update()
        {
            Velocity += Acceleration/*/Mass*/ * Time.ElapsedGameTime;                //Newton's Second Law - Ignore Mass computation for simplicity         
            Velocity += Impulse / Mass;                                     //Extension of Newton's Second Law: Application of forces for net value         It is important to add the impulse to the velocity before changing
            Transform.LocalPosition += Velocity * Time.ElapsedGameTime;     //Newton's First Law                                                            The local position to prevent adding energy to the system during
            Impulse = Vector3.Zero;                                         //When we apply a force, we want to apply it once then forget about it          collisions. This happens during the dot product calculation involving
        }                                                                   //                                                                              the collision normal and the difference of the velocities

        public Vector3 Velocity
        {
            get;
            set;
        }

        public float Mass
        {
            get;
            set;
        }

        public Vector3 Acceleration
        {
            get;
            set;
        }

        public Vector3 Impulse
        {
            get;
            set;
        }
    }
}
